import time

import requests
from config.config import *

def send_feishu_message():
    message_data = [
        [
            {
                "tag": "text",
                "text": f"项目名称:{PROJECT}",
            }
        ],
        [
            {
                "tag": "text",
                "text":f"执行时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}",
            }
        ],
        [
            {
                "tag": "text",
                "text":"详细信息:"
            },
            {
                "tag": "a",
                "text": "查看测试报告",
                "href": REPORT_PATH
            }
        ]
    ]
    payload = {
        "msg_type": "post",
        "content": {
            "post": {
                "zh_cn": {
                    "title": "自动化测试报告",
                    "content": message_data
                }
            }
        }
    }
    # 判断发送消息的开关
    if FEISHU_IS_SEND:
        response = requests.post(WEBHOOK, json=payload)
        return response

if __name__ == '__main__':
    send_feishu_message()

# # 1. 导入 requests
# import requests
# # 2. 定义 webhook 地址
# webhook = "xxxxx"
# # 3. 发送富文本消息
# # "tag":"text"      表示文本内容
# # "tag":"a"         表示超链接
# # "href":""         超链接跳转地址
# message_data=[
#     [
#         {
#             "tag":"text",
#             "text":"天辰 ERP 项目"
#         }
#     ],
#     [
#         {
#             "tag":"a",
#             "text":"查看测试报告",
#             "href":"http"
#         }
#     ]
# ]
# # 4. 构建最终的消息体
# payload = {
#     "msg_type": "post",
#     "content": {
#         "post":{
#             "zh_cn":{
#                 "title":"自动化测试报告",
#                 "content":message_data
#             }
#         }
#     }
# }
# # 5. 发送消息
# response = requests.post(webhook, json=payload)
#
# print(response.text)